//
//  CZQAddResumeViewController.m
//  coachmanage
//
//  Created by 众拳科技 on 2018/3/14.
//  Copyright © 2018年 众拳科技. All rights reserved.
//

#import "CZQAddResumeViewController.h"
#import "MOFSPickerManager.h"
#import "CZQAddJobExperView.h"
#import "CZQAddCerView.h"
#import "CZQAddStudyExperView.h"
#import "CZQAddEducationExperView.h"
@interface CZQAddResumeViewController ()<CZQAddStudyExperViewDelegate>
{
    
}
@property (nonatomic , strong) ZLPhotoPickerBrowserPhoto *photo;

//机构LOGO,url
@property (nonatomic , strong)NSString *logoUrl;

//证书url
@property (nonatomic , strong)NSString *cerUrl;

//记录头像还是证书图片选择
@property (nonatomic , assign)BOOL isIcon;
/**
 //工作经历
 */
@property(nonatomic,weak)CZQAddJobExperView *JobExperView;

/**
 //获得证书
 */
@property(nonatomic,weak)CZQAddCerView *CerView;

/**
 //学习培训
 */
@property(nonatomic,weak)CZQAddStudyExperView *StudyExperView;

/**
 //教育经历
 */
@property(nonatomic,weak)CZQAddEducationExperView *EducationExperView;


/**
数据
 */
@property(nonatomic,strong)NSMutableArray *dataArr;

@end

@implementation CZQAddResumeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self creatSubView];
    
    [self handleData];
    
    //有数据删除
    
    NSLog(@"%@==%ld",self.dic,self.row);
    if (self.dic ) {
        
        UIButton *sureBtn = [[UIButton alloc] init];
        [sureBtn setTitle:@"删除"];
        [sureBtn setTitleColor:CSColorFromRGB(0x0a0a0a)];
        sureBtn.titleLabel.font = MidBigFont;
        sureBtn.backgroundColor = ButtonBackGroundColor;
        [self.view addSubview:sureBtn];
        
        [sureBtn addTarget:self action:@selector(delete)];
        
        [sureBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.bottom.mas_equalTo(self.view).offset(-20);
            
            make.left.mas_equalTo(self.view).offset(20);
            
            make.right.mas_equalTo(self.view).offset(-20);
            
            make.height.mas_equalTo(50);
        }];
        
    }
    
}

-(void)handleData
{
    if (self.section == 4) {
        //工作经历
        self.dataArr = [NSMutableArray arrayWithArray:self.resumeModel._WorkExp];
    }else if (self.section == 5)
    {
        //获得证书
        self.dataArr = [NSMutableArray arrayWithArray:self.resumeModel._CertificateExp];
    }
    else if (self.section == 6)
    {
        //参加培训
        self.dataArr = [NSMutableArray arrayWithArray:self.resumeModel._TrainingExp];
    }
    
    else if (self.section == 7)
    {
        //教育经历
        self.dataArr = [NSMutableArray arrayWithArray:self.resumeModel._EducationExp];
    }
    
    
}


-(void)creatSubView
{
    
    //右侧按钮
    
    self.view.backgroundColor = BackGroundColor;
    
    UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(sureBtnClick)];
    
    [rightButtonItem setTitleTextAttributes:@{NSForegroundColorAttributeName:CSBlackColor,NSFontAttributeName:MidFont} forState:UIControlStateNormal];
    
    [rightButtonItem setTitleTextAttributes:@{NSForegroundColorAttributeName:CSBlackColor,NSFontAttributeName:MidFont} forState:UIControlStateHighlighted];
    
    self.navigationItem.rightBarButtonItem = rightButtonItem;
    
    
    
    
    //循环引用
    WS(weakSelf);
    
    if (self.section == 4){
        //工作经历
        
        CZQAddJobExperView *JobExperView = [[CZQAddJobExperView alloc] init];
        
        
        [self.view addSubview:JobExperView];
        
        //起始时间选择
        
        [JobExperView.startTimeBtnView.choseBtn bk_addEventHandler:^(id sender) {
            
            [self.view endEditing:YES];
            
            
            [[MOFSPickerManager shareManger] showDatePickerWithTag:68 title:@"选择起始时间"cancelTitle:@"取消" commitTitle:@"确定" datePickerMode:UIDatePickerModeDate commitBlock:^(NSDate *date) {
                
                //处理
                NSDateFormatter *objDateformat1 = [[NSDateFormatter alloc] init];
                [objDateformat1 setDateFormat:@"yyyy-MM-dd"];
                
                NSString *timestamp1 = [objDateformat1 stringFromDate: date];
                
                weakSelf.JobExperView.startTimeBtnView.choseLabel.text = timestamp1;
                
                weakSelf.JobExperView.startTimeBtnView.choseLabel.textColor = TFColor;
                
            } cancelBlock:^{
                
            }];
            
        } forControlEvents:UIControlEventTouchUpInside];
        
        
        //结束时间选择
        [JobExperView.endTimeBtnView.choseBtn bk_addEventHandler:^(id sender) {
            
            [self.view endEditing:YES];
            
            
            [[MOFSPickerManager shareManger] showDatePickerWithTag:69 title:@"选择结束时间"cancelTitle:@"取消" commitTitle:@"确定" datePickerMode:UIDatePickerModeDate commitBlock:^(NSDate *date) {
                
                //处理
                NSDateFormatter *objDateformat1 = [[NSDateFormatter alloc] init];
                [objDateformat1 setDateFormat:@"yyyy-MM-dd"];
                
                NSString *timestamp1 = [objDateformat1 stringFromDate: date];
                
                weakSelf.JobExperView.endTimeBtnView.choseLabel.text = timestamp1;
                
                weakSelf.JobExperView.endTimeBtnView.choseLabel.textColor = TFColor;
                
            } cancelBlock:^{
                
            }];
            
        } forControlEvents:UIControlEventTouchUpInside];
        
        
        
        
        [JobExperView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.edges.mas_equalTo(self.view);
        }];
        
        //self.userAccount = [UserAccount account];
        
        self.JobExperView = JobExperView;
        
        //赋值
        CZQWorkExpModel *work = [CZQWorkExpModel mj_objectWithKeyValues:self.dic];
        self.JobExperView.companyView.titleTF.text = work.CompanyName;
        self.JobExperView.jobNameView.titleTF.text = work.Position;
        self.JobExperView.startTimeBtnView.choseLabel.text = work.BeginDate ;
        self.JobExperView.endTimeBtnView.choseLabel.text = work.EndDate ;
        self.JobExperView.jobTitleView.titleTF.text = work.Intro ;
        
        
    }
    else if (self.section == 5){
        //获得证书
        
        CZQAddCerView *CerView = [[CZQAddCerView alloc] init];
        
        [self.view addSubview:CerView];
        
        
        
        
        //起始时间选择
        
        [CerView.startTimeBtnView.choseBtn bk_addEventHandler:^(id sender) {
            
            [weakSelf.view endEditing:YES];
            
            
            [[MOFSPickerManager shareManger] showDatePickerWithTag:58 title:@"选择生效时间"cancelTitle:@"取消" commitTitle:@"确定" datePickerMode:UIDatePickerModeDate commitBlock:^(NSDate *date) {
                
                //处理
                NSDateFormatter *objDateformat1 = [[NSDateFormatter alloc] init];
                [objDateformat1 setDateFormat:@"yyyy-MM-dd"];
                
                NSString *timestamp1 = [objDateformat1 stringFromDate: date];
                
                weakSelf.CerView.startTimeBtnView.choseLabel.text = timestamp1;
                
                weakSelf.CerView.startTimeBtnView.choseLabel.textColor = TFColor;
                
            } cancelBlock:^{
                
            }];
            
        } forControlEvents:UIControlEventTouchUpInside];
        
        
        //结束时间选择
        [CerView.endTimeBtnView.choseBtn bk_addEventHandler:^(id sender) {
            
            [weakSelf.view endEditing:YES];
            
            [[MOFSPickerManager shareManger] showPickerViewWithDataArray:@[@"选择时间",@"长期有效"] tag:67 title:@"选择失效" cancelTitle:@"取消" commitTitle:@"确定" commitBlock:^(NSString *string) {
                
                if ([string isEqualToString:@"长期有效"]) {
                    
                    weakSelf.CerView.endTimeBtnView.choseLabel.text = @"长期有效";
                    
                    weakSelf.CerView.endTimeBtnView.choseLabel.textColor = TFColor;
                    
                }else
                {
                    
                    [[MOFSPickerManager shareManger] showDatePickerWithTag:59 title:@"选择失效时间"cancelTitle:@"取消" commitTitle:@"确定" datePickerMode:UIDatePickerModeDate commitBlock:^(NSDate *date) {
                        
                        //处理
                        NSDateFormatter *objDateformat1 = [[NSDateFormatter alloc] init];
                        [objDateformat1 setDateFormat:@"yyyy-MM-dd"];
                        
                        NSString *timestamp1 = [objDateformat1 stringFromDate: date];
                        
                        weakSelf.CerView.endTimeBtnView.choseLabel.text = timestamp1;
                        
                        weakSelf.CerView.endTimeBtnView.choseLabel.textColor = TFColor;
                        
                    } cancelBlock:^{
                        
                    }];
                    
                }
                
            } cancelBlock:^{
                
            }];
            
            
            
        } forControlEvents:UIControlEventTouchUpInside];
        
        
        
        
        [CerView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.edges.mas_equalTo(self.view);
        }];
        
        //上传证书,获取
        
        [CerView.cerPhotoBtn bk_addEventHandler:^(id sender) {
            
            weakSelf.isIcon = NO;
            
            //选择证书
            [weakSelf logoSelect:sender];
            
            
        } forControlEvents:UIControlEventTouchUpInside];
        
        //self.userAccount = [UserAccount account];
        
        self.CerView = CerView;
        
        if (self.dic) {
            
            //赋值
            CZQCertificateExpModel *cer = [CZQCertificateExpModel mj_objectWithKeyValues:self.dic];
            self.CerView.companyView.titleTF.text = cer.Org;
            self.CerView.cerNameView.titleTF.text = cer.Name ;
            self.CerView.startTimeBtnView.choseLabel.text = cer.BeginDate ;
            self.CerView.endTimeBtnView.choseLabel.text =  cer.EndDate ;
            self.cerUrl = cer.Pic ;
            NSString *urlStr = [NSString stringWithFormat:@"%@%@",cer.Pic,mid_image];
            urlStr=[urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
            [CerView.cerPhotoBtn sd_setImageWithURL:[NSURL URLWithString:urlStr] forState:UIControlStateNormal];
            
        }
        
        
        
        
    }
    
    
    else if (self.section == 6){
        
        //学习培训
        CZQAddStudyExperView *StudyExperView = [[CZQAddStudyExperView alloc] init];
        
        [self.view addSubview:StudyExperView];
        
        //机构LOGO
        [StudyExperView.photoBtn bk_addEventHandler:^(id sender) {
            
            _isIcon = YES;
            
            [self logoSelect:sender];
            
        } forControlEvents:UIControlEventTouchUpInside];
        
        
        //起始时间选择
        
        [StudyExperView.startTimeBtnView.choseBtn bk_addEventHandler:^(id sender) {
            
            [self.view endEditing:YES];
            
            
            [[MOFSPickerManager shareManger] showDatePickerWithTag:68 title:@"选择起始时间"cancelTitle:@"取消" commitTitle:@"确定" datePickerMode:UIDatePickerModeDate commitBlock:^(NSDate *date) {
                
                //处理
                NSDateFormatter *objDateformat1 = [[NSDateFormatter alloc] init];
                [objDateformat1 setDateFormat:@"yyyy-MM-dd"];
                
                NSString *timestamp1 = [objDateformat1 stringFromDate: date];
                
                weakSelf.StudyExperView.startTimeBtnView.choseLabel.text = timestamp1;
                
                weakSelf.StudyExperView.startTimeBtnView.choseLabel.textColor = TFColor;
                
            } cancelBlock:^{
                
            }];
            
        } forControlEvents:UIControlEventTouchUpInside];
        
        
        //结束时间选择
        [StudyExperView.endTimeBtnView.choseBtn bk_addEventHandler:^(id sender) {
            
            [self.view endEditing:YES];
            
            
            [[MOFSPickerManager shareManger] showDatePickerWithTag:69 title:@"选择结束时间"cancelTitle:@"取消" commitTitle:@"确定" datePickerMode:UIDatePickerModeDate commitBlock:^(NSDate *date) {
                
                //处理
                NSDateFormatter *objDateformat1 = [[NSDateFormatter alloc] init];
                [objDateformat1 setDateFormat:@"yyyy-MM-dd"];
                
                NSString *timestamp1 = [objDateformat1 stringFromDate: date];
                
                weakSelf.StudyExperView.endTimeBtnView.choseLabel.text = timestamp1;
                
                weakSelf.StudyExperView.endTimeBtnView.choseLabel.textColor = TFColor;
                
            } cancelBlock:^{
                
            }];
            
        } forControlEvents:UIControlEventTouchUpInside];
        
        
        
        //证书生效时间
        [StudyExperView.cerView.startTimeBtnView.choseBtn bk_addEventHandler:^(id sender) {
            
            [weakSelf.view endEditing:YES];
            
            
            [[MOFSPickerManager shareManger] showDatePickerWithTag:68 title:@"选择生效时间"cancelTitle:@"取消" commitTitle:@"确定" datePickerMode:UIDatePickerModeDate commitBlock:^(NSDate *date) {
                
                //处理
                NSDateFormatter *objDateformat1 = [[NSDateFormatter alloc] init];
                [objDateformat1 setDateFormat:@"yyyy-MM-dd"];
                
                NSString *timestamp1 = [objDateformat1 stringFromDate: date];
                
                weakSelf.StudyExperView.cerView.startTimeBtnView.choseLabel.text = timestamp1;
                
                weakSelf.StudyExperView.cerView.startTimeBtnView.choseLabel.textColor = TFColor;
                
            } cancelBlock:^{
                
            }];
            
        } forControlEvents:UIControlEventTouchUpInside];
        
        StudyExperView.delegate = self;
        //机构LOGO获得证书
        
        
        
        
        [StudyExperView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.edges.mas_equalTo(self.view);
        }];
        
        //self.userAccount = [UserAccount account];
        
        self.StudyExperView = StudyExperView;
        
        if (self.dic) {
            
            CZQTrainingExpModel *train = [CZQTrainingExpModel mj_objectWithKeyValues:self.dic];
            
            self.StudyExperView.companyView.titleTF.text = train.Org ;
            self.logoUrl = train.Logo;
            self.StudyExperView.startTimeBtnView.choseLabel.text = train.BeginDate ;
            self.StudyExperView.endTimeBtnView.choseLabel.text = train.EndDate;
            self.StudyExperView.studyTitleView.titleTF.text = train.Content;
            self.StudyExperView.cerSwitchView.titleSwitch.on = [train.HasCert intValue] == 1?YES:NO;
            [self.StudyExperView switchAction:self.StudyExperView.cerSwitchView.titleSwitch];
            self.StudyExperView.cerView.companyView.titleTF.text = train.CertName;
            self.StudyExperView.cerView.startTimeBtnView.choseLabel.text = train.CertInvalidDate ;
            self.StudyExperView.cerView.endTimeBtnView.choseLabel.text = train.AwardInvalidDate;
            self.cerUrl = train.CertPics ;
             [StudyExperView.photoBtn sd_setImageWithURL:[NSURL URLWithString:[Helper imageUrlStringToChinese:self.logoUrl imageType:nil]] forState:UIControlStateNormal placeholderImage:PlaceHold];
            [StudyExperView.cerView.cerPhotoBtn sd_setImageWithURL:[NSURL URLWithString:[Helper imageUrlStringToChinese:self.cerUrl imageType:nil]] forState:UIControlStateNormal placeholderImage:PlaceHold];
            
        }
        
    }
    else if (self.section == 7){
        //教育经历
        
        CZQAddEducationExperView *EducationExperView = [[CZQAddEducationExperView alloc] init];
        
        [self.view addSubview:EducationExperView];
        
        //起始时间选择
        
        [EducationExperView.startTimeBtnView.choseBtn bk_addEventHandler:^(id sender) {
            
            [weakSelf.view endEditing:YES];
            
            
            [[MOFSPickerManager shareManger] showDatePickerWithTag:68 title:@"选择入校时间"cancelTitle:@"取消" commitTitle:@"确定" datePickerMode:UIDatePickerModeDate commitBlock:^(NSDate *date) {
                
                //处理
                NSDateFormatter *objDateformat1 = [[NSDateFormatter alloc] init];
                [objDateformat1 setDateFormat:@"yyyy-MM-dd"];
                
                NSString *timestamp1 = [objDateformat1 stringFromDate: date];
                
                weakSelf.EducationExperView.startTimeBtnView.choseLabel.text = timestamp1;
                
                weakSelf.EducationExperView.startTimeBtnView.choseLabel.textColor = TFColor;
                
            } cancelBlock:^{
                
            }];
            
        } forControlEvents:UIControlEventTouchUpInside];
        
        
        //结束时间选择
        [EducationExperView.endTimeBtnView.choseBtn bk_addEventHandler:^(id sender) {
            
            [self.view endEditing:YES];
            
            
            [[MOFSPickerManager shareManger] showDatePickerWithTag:69 title:@"选择毕业时间"cancelTitle:@"取消" commitTitle:@"确定" datePickerMode:UIDatePickerModeDate commitBlock:^(NSDate *date) {
                
                //处理
                NSDateFormatter *objDateformat1 = [[NSDateFormatter alloc] init];
                [objDateformat1 setDateFormat:@"yyyy-MM-dd"];
                
                NSString *timestamp1 = [objDateformat1 stringFromDate: date];
                
                weakSelf.EducationExperView.endTimeBtnView.choseLabel.text = timestamp1;
                
                weakSelf.EducationExperView.endTimeBtnView.choseLabel.textColor = TFColor;
                
            } cancelBlock:^{
                
            }];
            
        } forControlEvents:UIControlEventTouchUpInside];
        
        
        
        //学位
        [EducationExperView.degreeBtnView.choseBtn bk_addEventHandler:^(id sender) {
            
            [[MOFSPickerManager shareManger] showPickerViewWithDataArray:@[@"专科",@"本科",@"硕士",@"博士"] tag:70 title:@"选择学历" cancelTitle:@"取消" commitTitle:@"确定" commitBlock:^(NSString *string) {
                
                weakSelf.EducationExperView.degreeBtnView.choseLabel.text = string;
                
                weakSelf.EducationExperView.degreeBtnView.choseLabel.textColor = TFColor;
                
                //        weakSelf.userAccount.Sex = [string isEqualToString:@"男"]?@"0":@"1";
                
            } cancelBlock:^{
                
            }];
            
        } forControlEvents:UIControlEventTouchUpInside];
        
        
        [EducationExperView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.edges.mas_equalTo(self.view);
        }];
        
        //self.userAccount = [UserAccount account];
        
        self.EducationExperView = EducationExperView;
        
        //赋值
        if (self.dic) {
            
            CZQEducationExpModel *education = [CZQEducationExpModel mj_objectWithKeyValues:self.dic];
            self.EducationExperView.schoolNameView.titleTF.text = education.School;
            self.EducationExperView.majorView.titleTF.text = education.Profession;
            self.EducationExperView.startTimeBtnView.choseLabel.text = education.BeginDate;
            self.EducationExperView.endTimeBtnView.choseLabel.text = education.EndDate;
            self.EducationExperView.degreeBtnView.choseLabel.text = education.Degree;
            
        }
    }
    
    
}

#pragma mark - 图片选择

-(void)logoSelect:(UIButton *)photoSelect{
    
    
    WS(weakSelf);
    
    ZLPhotoPickerViewController *pickerVc = [[ZLPhotoPickerViewController alloc] init];
    
    pickerVc.maxCount = 1;
    
    // Jump AssetsVc
    pickerVc.status = PickerViewShowStatusCameraRoll;
    // Recoder Select Assets
    //    pickerVc.selectPickers = self.assets;
    // Filter: PickerPhotoStatusAllVideoAndPhotos, PickerPhotoStatusVideos, PickerPhotoStatusPhotos.
    
    pickerVc.photoStatus = PickerPhotoStatusPhotos;
    // Desc Show Photos, And Suppor Camera
    pickerVc.isShowCamera = YES;
    pickerVc.topShowPhotoPicker = YES;
    
    // CallBack
    
    pickerVc.callBack = ^(NSArray<ZLPhotoAssets *> *status){
        
        for (ZLPhotoAssets *assets in status) {
            
            ZLPhotoPickerBrowserPhoto *photo = [ZLPhotoPickerBrowserPhoto photoAnyImageObjWith:assets];
            
            photo.asset = assets;
            
//            weakSelf.photo = photo;
            
            UIImage *image;
            
            //拍照
            if ([photo.asset isKindOfClass:[UIImage class]]) {
                
                [photoSelect setImage:(UIImage *)photo.asset forState:UIControlStateNormal];
                image = (UIImage *)photo.asset;
            }
            else{
                
                [photoSelect setImage:[assets thumbImage] forState:UIControlStateNormal];
                image = [assets thumbImage];
            }
            
            [weakSelf uploadImage:image];
            
            break;
        }
    };
    
    [pickerVc showPickerVc:self];
    
}

#pragma mark 上传头像
-(void)uploadImage:(UIImage *)image{
    
    
    
    NSData *imageData;
    
    WS(weakSelf);
    
    
    imageData  = UIImageJPEGRepresentation(image,0.1);
    
    [MBProgressHUD showMessage:@"上传中.." toView:self.view];
    
    RAYUploader *upload = [RAYUploader defaultUploader];
    
    [upload uploadWithData:imageData complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
        
        [MBProgressHUD hideHUDForView:self.view];
        
        if (key) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                NSString *picUrl = [NSString stringWithFormat:@"%@%@",QiNiuBase,key];
                
                if (weakSelf.isIcon) {
                    weakSelf.logoUrl = picUrl;
                }else
                {
                    weakSelf.cerUrl = picUrl;
                }
                
                
                weakSelf.isIcon = NO;
            });
            
        }
        
    }];
    
}

#pragma mar - StudyExperViewDelegate
-(void)uploadCerPoto:(id)sender
{
    _isIcon = NO;
    
    [self logoSelect:sender];
    
}

#pragma mark - 删除
-(void)delete
{
    [self.dataArr removeObjectAtIndex:self.row];
    
//    if (self.section == 4) {
//        //工作经历
//        self.resumeModel._WorkExp = self.dataArr;
//    }else if (self.section == 5)
//    {
//        //获得证书
//        self.resumeModel._CertificateExp = self.dataArr ;
//    }
//    else if (self.section == 6)
//    {
//        //参加培训
//        self.resumeModel._TrainingExp = self.dataArr;
//    }
//
//    else if (self.section == 7)
//    {
//        //教育经历
//        self.resumeModel._EducationExp = self.dataArr ;
//    }
    
    
    [self updata];
    
    
}
#pragma mark - 确定

-(void)sureBtnClick
{
//    if (self.dic) {
//
//        [self.dataArr replaceObjectAtIndex:self.row withObject:self.dic];
//
//        return;
//    }
    if (self.section == 4) {
        //工作经历
        if ([self.JobExperView.companyView.titleTF.text isEmptyString]) {
            
            [MBProgressHUD showText:@"请输入工作单位" toview:self.view];
            
            return;
        }
        if ([self.JobExperView.jobNameView.titleTF.text isEmptyString]) {
            
            [MBProgressHUD showText:@"请输入岗位名称" toview:self.view];
            
            return;
        }
        if ([self.JobExperView.startTimeBtnView.choseLabel.text isEmptyString]) {
            
            [MBProgressHUD showText:@"请选择起始时间" toview:self.view];
            
            return;
        }
        if ([self.JobExperView.endTimeBtnView.choseLabel.text isEmptyString]) {
            
            [MBProgressHUD showText:@"请选择结束时间" toview:self.view];
            
            return;
        }
        if ([self.JobExperView.jobTitleView.titleTF.text isEmptyString]) {
            
            [MBProgressHUD showText:@"请输入工作详情" toview:self.view];
            
            return;
        }
        
        CZQWorkExpModel *work = [CZQWorkExpModel new];
        work.CompanyName = self.JobExperView.companyView.titleTF.text;
        work.Position = self.JobExperView.jobNameView.titleTF.text;
        work.BeginDate = self.JobExperView.startTimeBtnView.choseLabel.text;
        work.EndDate = self.JobExperView.endTimeBtnView.choseLabel.text;
        work.Intro = self.JobExperView.jobTitleView.titleTF.text;
        
        
        
        if (self.dic ) {
            [self.dataArr replaceObjectAtIndex:self.row withObject:[work toDictionary]];
        }else{
            [self.dataArr addObject:[work toDictionary]];
            
        }
        
//        self.resumeModel._WorkExp = self.dataArr ;
        
        NSLog(@"%@ == %@",self.resumeModel._WorkExp,self.dataArr);
        
    }else if (self.section == 5)
    {
        //获得证书
        if ([self.CerView.companyView.titleTF.text isEmptyString]) {
            
            [MBProgressHUD showText:@"请输入机构名称" toview:self.view];
            
            return;
        }
        if ([self.CerView.cerNameView.titleTF.text isEmptyString]) {
            
            [MBProgressHUD showText:@"请输入证书名称" toview:self.view];
            
            return;
        }
        if ([self.CerView.startTimeBtnView.choseLabel.text isEmptyString]) {
            
            [MBProgressHUD showText:@"请选择生效时间" toview:self.view];
            
            return;
        }
        if ([self.CerView.endTimeBtnView.choseLabel.text isEmptyString]) {
            
            [MBProgressHUD showText:@"请选择失效时间" toview:self.view];
            
            return;
        }
        if ([self.cerUrl isEmptyString]) {
            
            [MBProgressHUD showText:@"请选择证书" toview:self.view];
            
            return;
        }
        
        CZQCertificateExpModel *cer = [CZQCertificateExpModel new];
        cer.Org = self.CerView.companyView.titleTF.text;
        cer.Name = self.CerView.cerNameView.titleTF.text;
        cer.BeginDate = self.CerView.startTimeBtnView.choseLabel.text;
        cer.EndDate = self.CerView.endTimeBtnView.choseLabel.text;
        cer.Pic = self.cerUrl;
        if (self.dic ) {
            [self.dataArr replaceObjectAtIndex:self.row withObject:[cer toDictionary]];
        }else{
            [self.dataArr addObject:[cer toDictionary]];
            
        }
        
//        self.resumeModel._CertificateExp = self.dataArr ;
    }
    else if (self.section == 6)
    {
        //参加培训
        if ([self.StudyExperView.companyView.titleTF.text isEmptyString]) {
            
            [MBProgressHUD showText:@"请输入机构名称" toview:self.view];
            
            return;
        }
        if ([self.StudyExperView.studyTitleView.titleTF.text isEmptyString]) {
            
            [MBProgressHUD showText:@"请输入培训内容" toview:self.view];
            
            return;
        }
        if ([self.StudyExperView.startTimeBtnView.choseLabel.text isEmptyString]) {
            
            [MBProgressHUD showText:@"请选择生效时间" toview:self.view];
            
            return;
        }
        if ([self.StudyExperView.endTimeBtnView.choseLabel.text isEmptyString]) {
            
            [MBProgressHUD showText:@"请选择失效时间" toview:self.view];
            
            return;
        }
        if ([self.logoUrl isEmptyString]) {
            
            [MBProgressHUD showText:@"请选择机构LOGO" toview:self.view];
            
            return;
        }
        
        CZQTrainingExpModel *train = [CZQTrainingExpModel new];
        
        train.Org = self.StudyExperView.companyView.titleTF.text;
        train.Logo = self.logoUrl;
        train.BeginDate = self.StudyExperView.startTimeBtnView.choseLabel.text;
        train.EndDate = self.StudyExperView.endTimeBtnView.choseLabel.text;
        train.Content = self.StudyExperView.studyTitleView.titleTF.text;
        train.HasCert = self.StudyExperView.cerSwitchView.titleSwitch.isOn?@"1":@"0";
        train.CertName = self.StudyExperView.cerView.companyView.titleTF.text;
        train.CertInvalidDate = self.StudyExperView.cerView.startTimeBtnView.choseLabel.text;
        train.AwardInvalidDate = self.StudyExperView.cerView.endTimeBtnView.choseLabel.text;
        train.CertPics = self.cerUrl;
        if (self.dic ) {
            [self.dataArr replaceObjectAtIndex:self.row withObject:[train toDictionary]];
        }else{
            [self.dataArr addObject:[train toDictionary]];
            
        }

//        self.resumeModel._TrainingExp = self.dataArr;

    }
    
    else if (self.section == 7)
    {
        //教育经历
        if ([self.EducationExperView.schoolNameView.titleTF.text isEmptyString]) {
            
            [MBProgressHUD showText:@"请输入学校名字" toview:self.view];
            
            return;
        }
        if ([self.EducationExperView.majorView.titleTF.text isEmptyString]) {
            
            [MBProgressHUD showText:@"请输入专业名称" toview:self.view];
            
            return;
        }
        if ([self.EducationExperView.startTimeBtnView.choseLabel.text isEmptyString]) {
            
            [MBProgressHUD showText:@"请选择起始时间" toview:self.view];
            
            return;
        }
        if ([self.EducationExperView.endTimeBtnView.choseLabel.text isEmptyString]) {
            
            [MBProgressHUD showText:@"请选择结束时间" toview:self.view];
            
            return;
        }
        if ([self.EducationExperView.degreeBtnView.choseLabel.text isEmptyString]) {
            
            [MBProgressHUD showText:@"请选择学位" toview:self.view];
            
            return;
        }
        CZQEducationExpModel *education = [CZQEducationExpModel new];
        education.School = self.EducationExperView.schoolNameView.titleTF.text;
        education.Profession = self.EducationExperView.majorView.titleTF.text;
        education.BeginDate = self.EducationExperView.startTimeBtnView.choseLabel.text;
        education.EndDate =  self.EducationExperView.endTimeBtnView.choseLabel.text;
        education.Degree = self.EducationExperView.degreeBtnView.choseLabel.text;
        if (self.dic ) {
            [self.dataArr replaceObjectAtIndex:self.row withObject:[education toDictionary]];
        }else{
            [self.dataArr addObject:[education toDictionary]];
            
        }
//        [self.dataArr addObject:[education toDictionary]];
//        self.resumeModel._EducationExp = self.dataArr;
    }
    
    [self updata];
    
}


#pragma mark - 更新数据
    
-(void)updata
{
    
    [MBProgressHUD showMessage:@"请求中..." toView:self.view];
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    
    [params setDictionary:[self.resumeModel toDictionary]];
    
//    NSDictionary *params = [self.resumeModel toDictionary];
    if (self.section == 4) {
        //工作经历
        [params setObject:[self.dataArr JSONString] forKey:@"WorkExp"];

    }else if (self.section == 5)
    {
        //获得证书
        [params setObject:[self.dataArr JSONString] forKey:@"CertificateExp"];
    }
    else if (self.section == 6)
    {
        //参加培训
        [params setObject:[self.dataArr JSONString] forKey:@"TrainingExp"];
    }
    
    else if (self.section == 7)
    {
        //教育经历
        [params setObject:[self.dataArr JSONString] forKey:@"EducationExp"];
    }
    
    
    
    NSLog(@"%@",params);
    
    
    [HTTPTool POSTRaw:Post_Resume_Operate parameters:params
     
     
              success:^(id responseObject){
                  [MBProgressHUD showText:[responseObject objectForKey:@"Message"]];
                  NSLog(@"%@",responseObject);
                  [MBProgressHUD hideHUDForView:self.view];
                  
                  if (responseObject && [[responseObject objectForKey:@"Code"] intValue] == 0) {
                      
                      [MBProgressHUD showText:@"保存成功"];
                      
                      //发送一个通知
                      [[NSNotificationCenter defaultCenter] postNotificationName:@"resume" object:nil];
                      
                      if (self.section == 4) {
                          //工作经历
                          self.resumeModel._WorkExp = self.dataArr ;
                          
                      }else if (self.section == 5)
                      {
                          //获得证书
                          self.resumeModel._CertificateExp = self.dataArr ;
                          
                          //处理教练主页证书用的数据
                          self.resumeModel.CertificateExp = [self.dataArr JSONString];
                      }
                      else if (self.section == 6)
                      {
                          //参加培训
                          self.resumeModel._TrainingExp = self.dataArr ;

                      }
                      
                      else if (self.section == 7)
                      {
                          //教育经历
                          self.resumeModel._EducationExp = self.dataArr ;
                      }
                      
                      [self.navigationController popViewControllerAnimated:YES];
                  }
                  
                  
                  
              }
     
              failure:^(NSError *error){
                  
                  [MBProgressHUD hideHUDForView:self.view];
              }];
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
